Skip to content

Raise ValueError instead of tearing down CUDA when AuraFlow latents exceed pos_embed_max_size#13740

Open
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix-auraflow-pe-bounds
Open

Raise ValueError instead of tearing down CUDA when AuraFlow latents exceed pos_embed_max_size#13740
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix-auraflow-pe-bounds

Conversation

@Ricardo-M-L
Copy link
Copy Markdown
Contributor

Why

Fixes #12656.

When the input latent grid exceeds the pretrained positional embedding grid, pe_selection_index_based_on_dim silently produces negative / out-of-range gather indices. On CUDA this trips a vectorized_gather_kernel device-side assert, which destroys the CUDA context for the entire process and forces a Python restart.

Fix

Check the bounds up front and raise a `ValueError` with a clear message about the largest supported resolution, matching how `PatchEmbed.cropped_pos_embed` in `models/embeddings.py` handles the same situation for SD3.

```
AuraFlow positional embedding only supports up to N latent tokens
per axis, but got M. Reduce height/width below ...
```

Verification

13 LOC, 1 file. Pure error-path improvement — the happy path is unchanged. Without the fix the failure mode is a permanent CUDA tear-down requiring process restart; with it the user gets a clean exception they can catch.

…xceed pos_embed_max_size

When the input latent grid exceeds the pretrained positional embedding
grid, pe_selection_index_based_on_dim silently produces negative /
out-of-range gather indices. On CUDA this trips a
vectorized_gather_kernel device-side assert, which destroys the CUDA
context for the entire process and forces a Python restart (see huggingface#12656).

Check the bounds up front and raise a ValueError with a clear message
about the largest supported resolution, matching how PatchEmbed.cropped_pos_embed
in models/embeddings.py handles the same situation for SD3.

Fixes huggingface#12656
@github-actions github-actions Bot added size/S PR with diff < 50 LOC models fixes-issue and removed size/S PR with diff < 50 LOC labels May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Positional Embedding Index Out-of-Bounds in AuraFlow

1 participant